package cn.ffcs.uec.organization.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.uec.organization.dao.OrganizationRelationVoDao;
import cn.ffcs.uec.organization.vo.OrganizationRelationVo;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("organizationRelationVoDao")
public class OrganizationRelationVoDaoImpl extends BaseDaoImpl implements OrganizationRelationVoDao {

	@Override
	public PageInfo queryOrganization(OrganizationRelationVo organizationRelationVo, int currentPage, int pageSize) {
		StringBuilder sql = new StringBuilder();
		sql.append(" SELECT * FROM  VIEW_ORGANIZATION_RELATION v WHERE 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != organizationRelationVo) {
			if (!StrUtil.isNullOrEmpty(organizationRelationVo.getCode())) {
				sql.append(" AND V.code = ? ");
				params.add(organizationRelationVo.getCode());
			}
			if (!StrUtil.isNullOrEmpty(organizationRelationVo.getOrgName())) {
				sql.append(" AND V.orgName like ?");
				params.add("%" + StringEscapeUtils.escapeSql(organizationRelationVo.getOrgName()) + "%");
			}
			return super.jdbcFindPageInfo(sql.toString(), params, currentPage, pageSize, OrganizationRelationVo.class);
		}
		return null;
	}

}
